home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / General / Menu Events 1.1.2 / Menu Events Sample Script < prev    next >
Text File  |  1994-04-19  |  2KB  |  47 lines

  1. set dialogResult to display dialog "Which application?" ¬
  2.     default answer "" buttons {"Cancel", "Choose…", "OK"} default button 3
  3. if button returned of dialogResult is "Cancel" then error number -128
  4. if button returned of dialogResult is "OK" then
  5.     set targetApplication to application (text returned of dialogResult)
  6. else
  7.     set targetApplication to choose application
  8. end if
  9.  
  10. tell targetApplication
  11.     try
  12.         with timeout of 30 seconds -- some applications won't respond to Menu events
  13.             set menuListInfo to Query Menu List
  14.         end timeout
  15.     on error errorString number errorNumber
  16.         if errorNumber is -126 then -- dsMBarNFnd
  17.             error "Sorry, that program does not have a menu bar.  It may be background-only." number -126
  18.         else
  19.             error errorString number errorNumber
  20.         end if
  21.     end try
  22.     repeat with menuIndex from 1 to count of menuListInfo
  23.         if menu title of item menuIndex of menuListInfo = "File" then
  24.             if menu definition procedure resource id of item menuIndex of menuListInfo is not 0 then
  25.                 tell my application to display dialog ¬
  26.                     "Warning!  The File menu is non-standard." with icon 2
  27.             end if
  28.             set menuID to menu id of item menuIndex of menuListInfo
  29.             set menuInfo to Query Menu menu id menuID
  30.             repeat with menuItemID from 1 to count of menuInfo
  31.                 set menuItemInfo to item menuItemID of menuInfo
  32.                 if menu item enabled of menuItemInfo then
  33.                     tell my application to display dialog ¬
  34.                         "File menu item “" & (menu item text of menuItemInfo) & "” is enabled!"
  35.                 end if
  36.                 if menu item text of menuItemInfo = "Quit" then
  37.                     if menu item enabled of menuItemInfo then
  38.                         Select Menu Item menu id menuID menu item id menuItemID with option key -- Option-Quit
  39.                     else
  40.                         error "Sorry, the Quit item is disabled."
  41.                     end if
  42.                     return
  43.                 end if
  44.             end repeat
  45.         end if
  46.     end repeat
  47. end tell